package work.vcloud.baseinfo.controller;


import work.vcloud.frame.dao.OpenDao;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.*;

@RestController
@EnableScheduling
public class TimerController{

    @Resource
    private OpenDao openDao;

    /*定时查询错误信息调整*/
    @Scheduled(cron="0 */10 * * * ?")
    private void selectStudent() {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("sheet","sc_user_student");
            map.put("field","xjzh");
            for(int j=1;j<3;j++){
                map.put("type",j+"");
                map.put("sqlMapId", "error.selectStudentCode");
                List<Map<String,Object>> cardList =openDao.queryForList(map);
                if(cardList.size() > 0) {
                    for (int i = 0; i < cardList.size(); i++) {
                        Map<String, Object> card = cardList.get(i);
                        map.put("record",card.get("id"));
                        map.put("fk_unit",card.get("fk_unit"));
                        map.put("sqlMapId","error.select");
                        List<Map<String,Object>> repeatList =openDao.queryForList(map);
                        if(repeatList.size() == 0) {
                            map.put("sqlMapId","error.insert");
                            openDao.insert(map);
                        }
                    }
                }
            }
            map.put("field","sfzjh");
            for(int j=1;j<3;j++){
                map.put("type",j+"");
                map.put("sqlMapId", "error.selectStudentCard");
                List<Map<String,Object>> cardList =openDao.queryForList(map);
                if(cardList.size() > 0) {
                    for (int i = 0; i < cardList.size(); i++) {
                        Map<String, Object> card = cardList.get(i);
                        map.put("record",card.get("id"));
                        map.put("fk_unit",card.get("fk_unit"));
                        map.put("sqlMapId","error.select");
                        List<Map<String,Object>> repeatList =openDao.queryForList(map);
                        if(repeatList.size() == 0) {
                            map.put("sqlMapId","error.insert");
                            openDao.insert(map);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
